using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WebCrawlerApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void buttonSearch_Click(object sender, EventArgs e)
        {
            string keyword = textBoxKeyword.Text;
            string searchUrl = $"https://www.baidu.com/s?wd={Uri.EscapeDataString(keyword)}";

            List<string> phoneNumbers = await FetchPhoneNumbers(searchUrl);

            listBoxResults.Items.Clear();
            foreach (var number in phoneNumbers)
            {
                listBoxResults.Items.Add(number);
            }
        }

        private async Task<List<string>> FetchPhoneNumbers(string url)
        {
            List<string> phoneNumbers = new List<string>();

            using (var client = new HttpClient())
            {
                string response = await client.GetStringAsync(url);
                var matches = Regex.Matches(response, @"\d{3}-\d{4}-\d{4}");
                foreach (Match match in matches)
                {
                    phoneNumbers.Add(match.Value);
                }
            }

            return phoneNumbers;
        }
    }
}